<style>
.form-signin {
  max-width: 500px;
  padding: 15px;
  margin: 0 auto;
}
.form-signin .form-signin-heading,
.form-signin .checkbox {
  margin-bottom: 10px;
}
.form-signin .checkbox {
  font-weight: normal;
}
.form-signin .form-control {
  position: relative;
  height: auto;
  -webkit-box-sizing: border-box;
     -moz-box-sizing: border-box;
          box-sizing: border-box;
  padding: 10px;
  margin: 5px 0px 5px 0px;
  font-size: 16px;
}
.form-signin .form-control:focus {
  z-index: 2;
}
.form-signin input {
  margin-bottom: -1px;
  border-bottom-right-radius: 0;
  border-bottom-left-radius: 0;
}
.form-signin input[type="password"] {
  margin-bottom: 10px;
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}
</style>

<template>
  <div class="container" style="background: #4C637B;">
    <validator name='v'>
      <form class="form-signin" novalidate @submit.prevent="signIn()">
        <div>
            <!-- <img src="../../assets/logo1.png" class="center-block img-responsive"></img> -->
        </div>
        <h2 class="form-signin-heading text-center" style="color: #fff;">安检系统</h2>
        <h4 class="form-signin-heading text-center" style="color: #fff;">欢迎使用移动安检系统</h4>
        <!-- <h5 class="form-signin-heading text-center" @click="backupDatabase">当前版本：0.{{version}}</h5> -->
        <input id="ename" style="margin-top: 100px;" class="form-control" placeholder="请输入用户名" autofocus v-model="ename" v-validate:ename='{ required: true }'>
        <input type="password"  id="inputPassword" class="form-control" placeholder="请输入密码" v-model="password" v-validate:password='{ required: true }'>
        <button :disabled="!$v.valid" class="btn btn-lg btn-success btn-block" type="submit" style="color: #fff;background-color: #67BA2F; border-color: #67BA2F;">登录</button>
      </form>
    </validator>
    <div class="login-footer login-footer_fixed-bottom">
        <p class="login-footer__links">
            <a href="javascript:home();" class="login-footer__link"></a>
        </p>
        <p class="login-footer__text">Copyright @ v1.0.0 榆林</p>
    </div>
  </div>
</template>
<script>
import Vue from 'vue'

export default {
  title: '登录系统',
  data() {
    return {
      ename: '',
      password: ''
    }
  },
  ready () {
//     // https://tc39.github.io/ecma262/#sec-array.prototype.findIndex
//     window.alert('11111111111')
//     window.alert('进来之后的判断内容',!Array.prototype.findIndex)
//     window.alert('222222222222222')
//     if (!Array.prototype.findIndex) {
//       Object.defineProperty(Array.prototype, 'findIndex', {
//       value: function(predicate) {
//      // 1. Let O be ? ToObject(this value).
//       if (this == null) {
//         throw new TypeError('"this" is null or not defined');
//       }
//       var o = Object(this);
//       // 2. Let len be ? ToLength(? Get(O, "length")).
//       var len = o.length >>> 0;
//
//       // 3. If IsCallable(predicate) is false, throw a TypeError exception.
//       if (typeof predicate !== 'function') {
//         throw new TypeError('predicate must be a function');
//       }
//
//       // 4. If thisArg was supplied, let T be thisArg; else let T be undefined.
//       var thisArg = arguments[1];
//
//       // 5. Let k be 0.
//       var k = 0;
//
//       // 6. Repeat, while k < len
//       while (k < len) {
//         // a. Let Pk be ! ToString(k).
//         // b. Let kValue be ? Get(O, Pk).
//         // c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)).
//         // d. If testResult is true, return k.
//         var kValue = o[k];
//         if (predicate.call(thisArg, kValue, k, o)) {
//           return k;
//         }
//         // e. Increase k by 1.
//         k++;
//       }
//
//       // 7. Return -1.
//       return -1;
//     }
//   })
// }
//   window.alert('浏览器版本',navigator.userAgent)
      if(Vue.android) {
        let version = HostApp.getAppVersion().data
        this.$set('version', version)
      }
  },
  methods: {
    backupDatabase () {
        HostApp.backupDatabase()
    },
    signIn() {
      let result
        result = HostApp.login(this.ename, this.password)
      if(result.code == 200) {
        let res
        res = result.result
        Vue.orgs = res.orgs
        Vue.user = res.orgs[res.orgs.length-1]
        Vue.dataDir = res.dataDir
        Vue.sdDir = res.sddir

        this.$goto("nav-bottom", result, 'self')
      }
      else {
        HostApp.alert('登录失败。')
      }
      // this.$goto("nav-bottom")
    }
  }
}
</script>
<style scoped>
  .login-footer_fixed-bottom {
    height: auto;
    position: fixed;
    bottom: .52em;
    left: 0;
    right: 0;
  }
  .login-footer {
    color: #999;
    font-size: 14px;
    text-align: center;
  }
  .login-footer__link {
    color: #586C94;
  }
</style>
